package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;

import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysInitialRole;
import com.ruoyi.system.service.ISysInitialRoleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 初始角色Controller
 * 
 * @author zjf
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/initial")
public class SysInitialRoleController extends BaseController
{
    @Autowired
    private ISysInitialRoleService sysInitialRoleService;

    /**
     * 查询初始角色列表
     */
    @RequiresPermissions("system:initial:list")
    @GetMapping("/list")
    public TableDataInfo list(SysInitialRole sysInitialRole)
    {
        startPage();
        List<SysInitialRole> list = sysInitialRoleService.selectSysInitialRoleList(sysInitialRole);
        return getDataTable(list);
    }

    /**
     * 导出初始角色列表
     */
    @RequiresPermissions("system:initial:export")
    @Log(title = "初始角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysInitialRole sysInitialRole)
    {
        List<SysInitialRole> list = sysInitialRoleService.selectSysInitialRoleList(sysInitialRole);
        ExcelUtil<SysInitialRole> util = new ExcelUtil<SysInitialRole>(SysInitialRole.class);
        util.exportExcel(response, list, "初始角色数据");
    }

    /**
     * 获取初始角色详细信息
     */
    @RequiresPermissions("system:initial:query")
    @GetMapping(value = "/{initialId}")
    public AjaxResult getInfo(@PathVariable("initialId") Long initialId)
    {
        return success(sysInitialRoleService.selectSysInitialRoleByInitialId(initialId));
    }

    /**
     * 新增初始角色
     */
    @RequiresPermissions("system:initial:add")
    @Log(title = "初始角色", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysInitialRole sysInitialRole)
    {
        return toAjax(sysInitialRoleService.insertSysInitialRole(sysInitialRole));
    }

    /**
     * 修改初始角色
     */
    @RequiresPermissions("system:initial:edit")
    @Log(title = "初始角色", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysInitialRole sysInitialRole)
    {
        return toAjax(sysInitialRoleService.updateSysInitialRole(sysInitialRole));
    }

    /**
     * 删除初始角色
     */
    @RequiresPermissions("system:initial:remove")
    @Log(title = "初始角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{initialIds}")
    public AjaxResult remove(@PathVariable Long[] initialIds)
    {
        return toAjax(sysInitialRoleService.deleteSysInitialRoleByInitialIds(initialIds));
    }


    /**
     * 修改角色状态
     */

    @PermitAll
    @PostMapping("/operate")
    public AjaxResult changeStatus(@RequestParam Long initialId,  String initialStatus){

        return toAjax(sysInitialRoleService.changeRoleStatus(initialId,initialStatus));
    }

}
